package com.c2c.controller.user;


import com.c2c.po.User;
import com.c2c.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/update")
public class UserBuyController {

    @Autowired
    private AccountService accountService;

    //修改个人信息
    @RequestMapping("/updateUser")
    public String update(User user, HttpSession httpSession) {
        User userAccount = (User) httpSession.getAttribute("userAccount");
        user.setUserAccount(userAccount.getUserAccount());
        User byUserAccount = accountService.findByUserAccount(user.getUserAccount());
        if (byUserAccount != null) {
            accountService.updateUserByUserAccount(user);
            httpSession.removeAttribute("userAccount");
            User byUserAccount1 = accountService.findByUserAccount(user.getUserAccount());
            httpSession.setAttribute("userAccount", byUserAccount1);
        }
        return "redirect:/userSell/MyGoods";
    }

}
